﻿namespace BadHabit.WPFTools.Converters
{
    using System;
    using System.Globalization;
    using System.Windows.Data;

    [ValueConversion(typeof(object), typeof(Int16))]
    public class LocalizeConverter : IValueConverter
    {
        public static System.Resources.ResourceManager ResourceManager { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (ResourceManager == null)
            {
                return value;
            }

            if (value == null)
            {
                return null;
            }

            object loc = ResourceManager.GetObject(value.ToString());
            if (loc == null)
            {
                return value.ToString();
            }

            return loc.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
